Common
api.ledControl(state)
- Overview
- Arguments
- Example
Turns ON or OFF the on board LED. It can be also used for debugging purposes.
- state (integer) - sets LED state (1=ON, 0=OFF)
--turns on blue LED
api.ledControl(1)
api.delayms(ms)
- Overview
- Arguments
- Example #1
- Example #2
Pause the execution for ms milliseconds.
- ms (integer) - The number of milliseconds to delay
api.delayms(1000) --delay one second
api.ledControl(1) -- turn on blue LED
api.delayms(1000) -- wait 1 second
api.ledControl(0) -- turn off blue LED
api.randInt(min, max)
- Overview
- Arguments
- Return
- Example
Generate random number within given range.
Available only for LoRaWAN devices (function uses it's module to generate random number)
- min (integer) - beginning number of the interval
- max (integer) - end number of the interval
- number (Integer)
-- generates random number within interval from 5 to 20
ran=api.randInt(5, 20)
api.getUniqueNumber()
- Overview
- Return
- Example
Returns an unique integer number in range (in range from 0 to 2^32)*.
- num (integer) - Unique number
--get an unique number
num = api.getUniqueNumber()
api.getBatteryVoltage()
- Overview
- Return
- Example
Get curent battery voltage in mV.
- voltage (Integer)
--get battery voltage value in mV
mv = api.getBatteryVoltage()
api.getTick()
- Overview
- Return
- Example
Returns current number of milliseconds since startup. Counts up to 2^32 and then restarts from 0.
- tick (integer) - Number of milliseconds since startup of the device
--get a timestamp, can be used for timing
timestamp = api.getTick()
-- to show the amount of milliseconds you can use print() function
print(timestamp)
api.dumpArray(str)
- Overview
- Arguments
- Example
Prints contents of variable as hexadecimal string (dumps array into console)
- str (string) - variable to print
--print string "123ef" as hexadecimal
api.dumpArray("123ef")
--OUTPUT 00 : 31 32 33 65 66
api.float(op,form,arg1,arg2)
- Overview
- Arguments
- Return
- Example #1
- Example #2
Performs operation with given floating point data.
Only if it's allowed by the firmware.
- op (string) - The operation to perform (“add” - addition, “sub” - substraction of arg2 from arg1, “mul” - multiplication, “div” - division of arg1 by arg2, “coerce” - coercion, unary operation using only arg1)
- form (string) - Two or three characters specifying the format of input/output data. - first position is for arg1. - second either specifies the format of arg2 or if last, specifies the format of return data, which are the same - by adding “N” to end of a string it coerces and returns little endian integer (OPTIONAL)
- arg1 (string) - The first operation argument, formated as specified in format.
- arg2 (string) - The second operation argument, formated as specified in format.
- result (string, integer) - Returns result of operation, either 4 bytes little/big endian (depends on form parameter) IEEE 754 float or string float representation or integer value
-- Multiply IEE 754 float with a floating point constant and return coerced value
-- S - string float representation, e.g. “2.234”
-- B - binary little endian IEEE 754 representation as 4 characters/bytes in a string
ret = api.float("mul", "SSN", "12.8", "1000.0")
print(ret)
-- output = 12800
ret = api.float("mul", "SSS", "12.8", "1000.0")
print(ret)
-- output = 12800.0000
-- hexadecimal interpretation of a number 12.8 is 0x414CCCCD (IEE 754)
x=string.char(0xCD,0xCC,0x4C,0x41)
ret = api.float("mul", "BSS", x, "1000.0")
print(ret)
-- output = 12800.0000
api.setVar(index, value)
- Overview
- Arguments
- Example
Saves a persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to write, 0 to 15 is available for RAM variables (lost on reset), 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and 48 to 1071 is available for variables stored in EEPROM (100k writes).
- value (integer) - Value to store at index
--set persistent variable value from index 1000 to value of 3424
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
api.setVar(1000, 3424)
api.getVar(index)
- Overview
- Arguments
- Returns
- Example
Returns persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to read, 0 to 15 is available for RAM variables (lost on reset), 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and 48 to 1071 is available for variables stored in EEPROM (100k writes).
- value (integer) - Value of the 32bit variable
--get persistent variable value from index 1000
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
slotNumber = api.getVar(1000)
api.wakeUpAt(day, hour, minute, second)
- Overview
- Arguments
- Return
- Example
Schedules the next wake up event of the device to provided day of month (day), hour, minute and second. The provided wake up date is therefore absolute and not relative as in wakeUpIn().
- day (integer) - Day of month, range 1 to 31
- hour (integer) - Hour, range 0 to 23
- minute (integer) - Minute, range 0 to 59
- second (integer) - Second, range 0 to 59
- resetOnFail (integer) - Reboot device when setting of wake-up event failed (1 - true, 0 or nothing - false)
- status (integer) - Execution status, 0 for success and -1 for error
--schedules next wake up to the 25th, 2:22:58
status = api.wakeUpAt(25, 2, 22, 58)
api.wakeUpIn(day, hour, minute, second)
- Overview
- Arguments
- Return
- Example
Schedules the next wake up event of the device after specified time interval. The provided wake up date is therefore relative and not absolute as in wakeUpAt(). Note: The input arguments are not limited, but the total period specified must not exceed 31 days. (e.g. hour = 40, days = 2 gives a period of 3 days and 16 hours).
- day (integer) - Day, range from 0 to 31
- hour (integer) - Hour, range 0 to X
- minute (integer) - Minute, range 0 to X
- second (integer) - Second, range 0 to X
- resetOnFail (integer) - Reboot device when setting of wake-up event failed (1 - true, 0 or nothing - false)
- status (integer) - Execution status, 0 for success and -1 for error
--schedules next wake up in 1 day and 122 minutes
status = api.wakeUpIn(1, 0, 122, 0)
api.getTimeDate()
- Overview
- Return
- Example
Returns current date and time set on this device. The time can be synchronized over LoRa, or when uploading LUA script using LUA scripting interface.
- year (integer) - Current year
- month (integer) - Current month
- day (integer) - Current day of month
- hour (integer) - Current hour
- minute (integer) - Current minute
- second (integer) - Current second
--read current date and time
y,M,d,h,m,s = api.getTimeDate()
api.setTimeDate(year, month, day, hour, minute, second)
- Overview
- Arguments
- Example
Set date and time on this device.
- year (integer)
- month (integer)
- day (integer)
- hour (integer)
- minute (integer)
- second (integer)
--set date and time
api.getTimeDate(2022, 1, 31, 24, 59, 0)